//AES 加密
globalThis.encryptAES = function (plaintext) {
    const keyBytes = CryptoJS.enc.Utf8.parse("xxm9N4P9rS2zjdyz");
    const ivBytes = CryptoJS.enc.Utf8.parse("xxm9N4P9rS2zjdyz");
    try {
        const encrypted = CryptoJS.AES.encrypt(
            plaintext,
            keyBytes,
            {
                iv: ivBytes,
                mode: CryptoJS.mode.CBC,
                padding: CryptoJS.pad.Pkcs7
            }
        );
        return encrypted.toString() || '';
    } catch (error) {
        console.error('AES 加密失败:', error.message);
        return '';
    }
}
//AES 解密
globalThis.decryptAES = function (ciphertext) {
    const keyBytes = CryptoJS.enc.Utf8.parse("xxm9N4P9rS2zjdyz");
    const ivBytes = CryptoJS.enc.Utf8.parse("xxm9N4P9rS2zjdyz");
    try {
        const decrypted = CryptoJS.AES.decrypt(
            ciphertext,
            keyBytes,
            {
                iv: ivBytes,
                mode: CryptoJS.mode.CBC,
                padding: CryptoJS.pad.Pkcs7
            }
        );
        return decrypted.toString(CryptoJS.enc.Utf8) || '';
    } catch (error) {
        console.error('AES 解密失败:', error.message);
        return '';
    }
}


var rule = {
	title:'追剧猫',
	host:'http://103.109.20.117:6699',
	homeUrl:'/api.php/getappapi.index/initv119',
	url:'/api.php/getappapi.index/typeFilterVodList?page=fypage&type_id=fyclass&class=全部&area=全部&lang=全部&year=全部&sort=最新',
	detailUrl:'/api.php/getappapi.index/vodDetail?vod_id=fyid',
	searchUrl:'/api.php/getappapi.index/searchList?type_id=0&keywords=**&page=fypage',
  class_name:'电影&电视剧&综艺&动漫&短剧&少儿&纪录片',
  class_url: '2&1&4&3&5&6&12',
  searchable: 2,//是否启用全局搜索,
  quickSearch: 0,//是否启用快速搜索,
  filterable: 0,//是否启用分类筛选,
  timeout: 5000,
  推荐: $js.toString(() => {
  	let d = [];
    let str=fetch(input);
    let list=JSON.parse(decryptAES(JSON.parse(str).data)).recommend_list;
    list.forEach(it => {
      d.push({
        url:it.vod_id,
        title: it.vod_name,
        desc: it.vod_remarks,
        img: it.vod_pic
      })
    });
    setResult(d);
  }),
  一级: $js.toString(() => {
  	let d = [];
    let str=fetch(input);
    let list=JSON.parse(decryptAES(JSON.parse(str).data)).recommend_list;
    list.forEach(it => {
      d.push({
        url:it.vod_id,
        title: it.vod_name,
        desc: it.vod_remarks,
        img: it.vod_pic
      })
    });
    setResult(d);
  }),
  二级:$js.toString(() => {
    let str=fetch(input);
    let jsony=JSON.parse(decryptAES(JSON.parse(str).data)).vod;
    let bfxl=JSON.parse(decryptAES(JSON.parse(str).data));
    
    let ktabs = bfxl.vod_play_list.map((it) => { return '' + it.player_info.show });
		let kurls = bfxl.vod_play_list.map((item) => {
			let kurl = item.urls.map((it) => { return `${it.name}$${it.url}*${it.parse_api_url}*${it.token}*${item.player_info.show}`});// *${item.player_info.show}
			return kurl.join('#')
		});
    VOD = {
      vod_name:jsony.vod_name,
      type_name: jsony.vod_class,
      vod_pic: jsony.vod_pic,
      vod_remarks: jsony.vod_remarks,
      vod_year: jsony.vod_year,
      vod_area:jsony.vod_area,
      vod_lang:jsony.vod_lang,
      vod_actor:jsony.vod_actor,
      vod_content:jsony.vod_content+input,
      vod_play_from: ktabs.join('$$$'),
      vod_play_url: kurls.join('$$$')    //"https://v.lzcdn27.com/20251114/2301_eeab88b6/index.m3u8"
    };
  }),
  play_parse: true,
	lazy: $js.toString(() => {
		let kurl = input.split('*')[0];
		let ktab = input.split('*')[1];
		let token = input.split('*')[2];
		let ktab1 = input.split('*')[3];
		if (/\.m3u8/.test(kurl)) {
			input = { jx: 0, parse: 0, url: kurl }
		} else if (/NBY/.test(kurl)) {
			kurl = JSON.parse(fetch(ktab)).url;
			input = { jx: 0, parse: 0, url: kurl }
		} else if (/rose|knmb|mtv|YYNB|QingShan|Ace/.test(kurl)) {
			let jm =encryptAES(kurl).replaceAll("+","%2B");
			let parse_api = ktab.slice(0, 32);
			kurl = HOST+`/api.php/getappapi.index/vodParse?url=${jm}${"&token="}${token}${"&parse_api="}${parse_api}`;
			kurl = JSON.parse(fetch(kurl)).data;
			kurl = JSON.parse(JSON.parse(decryptAES(kurl)).json).url;
			input = { jx: 0, parse: 0, url: kurl }
		} else if (/TY蓝光/.test(ktab1)) {
			let jm =encryptAES(kurl).replaceAll("+","%2B");
			let parse_api = ktab.slice(0, 32);
			kurl = HOST+`/api.php/getappapi.index/vodParse?url=${jm}${"&token="}${token}${"&parse_api="}${parse_api}`;
			kurl = JSON.parse(fetch(kurl)).data;
			kurl = JSON.parse(JSON.parse(decryptAES(kurl)).json).url;
			input = { jx: 0, parse: 0, url: kurl }
		} else {
			input = { jx: 1, parse: 1, url: kurl }
		}
	}),
  搜索: $js.toString(() => {
  	let d = [];
    let str=fetch(input);
    let list=JSON.parse(decryptAES(JSON.parse(str).data)).search_list;
    list.forEach(it => {
      d.push({
        url:it.vod_id,
        title: it.vod_name,
        desc: it.vod_remarks,
        img: it.vod_pic
      })
    });
    setResult(d);
  })
}